package com.company.threads.lockdemo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaohutu
 * @Description: 死锁
 * @date 2021/1/15 16:05
 */
public class DeadLock {
    DeadLock parent = null;
    List children = new ArrayList();

    public synchronized void addChild(DeadLock deadLock) {
        if (!this.children.contains(deadLock)) {
            this.children.add(deadLock);
        }
    }

    public synchronized void addChildOnly(DeadLock child) {
        if (!this.children.contains(child)) {
            this.children.add(child);
        }
    }

    public synchronized void setParent(DeadLock parent) {
        this.parent = parent;
        parent.addChildOnly(this);
    }

    public synchronized void setParentOnly(DeadLock parent) {
        this.parent = parent;
    }

}
